package com.cjg.Class;

import java.lang.annotation.*;
import java.lang.reflect.Field;

public class demo11 {
    public static void main(String[] args) throws ClassNotFoundException, NoSuchFieldException {
        Class<?> aClass = Class.forName("com.cjg.Class.My");
        Annotation[] annotations = aClass.getAnnotations();
        for (Annotation annotation : annotations) {
            System.out.println(annotation);
        }

        //获取value值
        Table annotation = aClass.getAnnotation(Table.class);
        System.out.println(annotation.value());

        // 获得指定注解
        Field name = aClass.getDeclaredField("name");
        file annotation1 = name.getAnnotation(file.class);
        System.out.println(annotation1.columnName());


    }
}
@Table("db_my")
class My{
    @file(columnName = "table_id",type = "int",length = 10)
    private  int id;
    @file(columnName = "table_co",type = "int",length = 10)
    private  int age;
    @file(columnName = "table_name",type = "String",length = 10)
    private  String name;

    @Override
    public String toString() {
        return "My{" +
                "id=" + id +
                ", age=" + age +
                ", name='" + name + '\'' +
                '}';
    }

    public My(int id, int age, String name) {
        this.id = id;
        this.age = age;
        this.name = name;
    }

    public My() {
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }
}
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@interface  Table{
    String value();
}
@Target(ElementType.FIELD)
@Retention(RetentionPolicy.RUNTIME)
@interface file{
    String columnName();
    String type();
    int length();
}